/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package animation;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;

/**
 * @author AJF
 */
public class AnimationMidlet extends MIDlet implements CommandListener {

    private Display display;          // Reference to display
    private AnimationCanvas canvas;   // Game canvas
    private Command cmExit;           // Exit command

    public AnimationMidlet() {
        display = Display.getDisplay(this);

        cmExit = new Command("Exit", Command.EXIT, 1);

        // Create game canvas and exit command
        if ((canvas = new AnimationCanvas()) != null) {
            canvas.addCommand(cmExit);
            canvas.setCommandListener(this);
        }
    }

    public void startApp() {
        if (canvas != null) {
            display.setCurrent(canvas);
            canvas.start();
        }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        canvas.stop();
    }

    public void commandAction(Command c, Displayable s) {
        if (c == cmExit) {
            destroyApp(true);
            notifyDestroyed();
        }
    }
}
